package 数组.middle;

/**
 * @author Lw中
 * @date 2020/8/16 13:33
 */
public class YiSiSanQi {

    public static boolean kLengthApart(int[] nums, int k) {
        int n = 0;
        int[] arr = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
           if (nums[i] == 1) {
               arr[n++] = i;
           }
        }
        for (int i = 0; i < n-1; i++) {
            if (arr[i+1] - arr[i] < k+1) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int[] arr = {1,0,0,0,1,0,0,1};
        boolean b = kLengthApart(arr, 2);
        System.out.println(b);
    }

}
